/**
 * bindOa.html
 */
$(function() {
	//查询是否已绑定过OA账号
	$.ajax({
		url : rootPath + "/userFront/queryHrmResourceBySelf",
		method : "GET",
		success : function(data) {
			if(data.returnCode == '0000') {
				window.location.href = oaUrl;
			} else if(data.returnCode == '1001') {
				//未登录时 重新加载页面
				window.location.reload();
			}
		},
		error: function (jqXHR, textStatus, errorThrown) {
		}
	});
	
	// 回车登录
	$(document).keyup(
		function(event) {
			if (event.keyCode == 13) {
				bindOa();
			}
		}
	);

	$("#bindOa").click(function() {
		bindOa();
	});
})

//绑定oa账号
function bindOa() {
	var loginid = $.trim($("#username_input").val());
	if(loginid == '') {
		showMsg("请输入OA账号");
		return;
	}
	$.ajax({
		url : rootPath + "/userFront/bindOaAccount",
		method : "POST",
		data : {
			"loginid" : loginid
		},
		success : function(data) {
			if(data.returnCode == '0000') {
				layer.msg("绑定成功",{icon:1,time:1000},function() {
					window.location.href = oaUrl;					
				});
			} else {
				showMsg(data.returnMessage);
			}
		},
		error: function (jqXHR, textStatus, errorThrown) {
		}
	});
}